Skip to content

Prefer the detected command over generic ConPTY/cmd.exe titles, and detect cmd.exe + Git Bash prompts#103

Merged
nedtwigg merged 3 commits into
mainfrom
conpty-titles
May 27, 2026
Merged

Prefer the detected command over generic ConPTY/cmd.exe titles, and detect cmd.exe + Git Bash prompts#103
nedtwigg merged 3 commits into
mainfrom
conpty-titles

Conversation

@nedtwigg
Copy link
Copy Markdown
Member

Follow-up to #102 (command detection from the rendered prompt line), covering Windows shells and ConPTY title noise. These commits were developed alongside #102 but left out of that merge.

Problem

On Windows, ConPTY relays a console process's title for every process — frequently just its image path — whether or not the app set a meaningful one. Combined with cmd.exe's habit of titling itself, this clobbered the detected command. And cmd.exe / Git Bash prompts weren't detected at all, so commands on those shells never got a title (stuck at <idle>), which also meant a real app title (e.g. claude) never surfaced.

Changes

  1. Keep the detected command over generic ConPTY process-path titles. A bare executable path (C:\WINDOWS\system32\cmd.exe) or shell name doesn't override the detected command; descriptive app titles (lazygit: dormouse, README.md - VIM, claude's title) still do.

  2. Detect cmd.exe and Git Bash prompts. cmd.exe's C:\path> ends in the terminator with no trailing space (added a drive-letter-path branch); Git Bash's two-line prompt ends in a bare $ validated against the user@host MINGW64 /path context line above it.

  3. Strip cmd.exe's interpreter prefix. cmd sets its title to <path>\cmd.exe - <command> while running; treat a <generic interpreter path> - <rest> title as cmd announcing itself and keep <rest>, so the clean command shows.

Verified live (Windows)

Shell pnpm dev:website claude (OSC 0)
PowerShell
Git Bash
cmd.exe

Testing

516 unit tests pass (new cases: generic ConPTY path, bare-shell-name, cmd.exe prefix strip, cmd.exe prompt, Git Bash two-line prompt, and a no-context negative); tsc -b clean; VSCode extension builds.

Note

This is the per-shell prompt/title heuristic layer; OSC 633 shell-integration injection remains the durable fix and is intended as its own PR.

🤖 Generated with Claude Code

nedtwigg and others added 3 commits May 27, 2026 15:41
On Windows, ConPTY relays a console process's image path as an OSC 0/2
title for every process whether or not it set one — e.g. pnpm's script
shell (cmd.exe) broadcasts C:\WINDOWS\system32\cmd.exe, which overrode the
detected "pnpm dev:website". Such bare executable paths and shell names
carry no command information, so terminalTitleForCommand now ignores them
and falls back to the detected command. Descriptive app titles (anything
with arguments or text, e.g. "lazygit: dormouse", "README.md - VIM") still
override the command as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Both shells failed prompt detection, so no prompt shape was ever learned,
no command was detected, and the header stayed <idle> — which also meant a
meaningful OSC 0 title (e.g. from claude) never surfaced, since titles are
shown through a detected command.

- cmd.exe: `C:\path>` ends in the terminator with no trailing space, which
  the generic `[$#%>]\s$` branch rejects. Add a drive-letter-path branch.
- Git Bash: its two-line prompt ends in a bare `$ ` (the user@host/path
  context is on the line above). Accept a bare-terminator final line when
  the preceding non-blank line carries prompt context.

With detection working, commands on these shells get titled and an app's
OSC title (claude, vim, …) overrides via the existing command path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cmd.exe sets its console title to "<path>\cmd.exe - <command>" while a
command runs, which ConPTY relays as OSC 0 (e.g.
"C:\WINDOWS\system32\cmd.exe - pnpm dev:website"). That has spaces so it
read as a meaningful title and overrode the detected command with the
verbose version. Treat a "<generic interpreter path> - <rest>" title as
the interpreter announcing itself: strip the prefix and keep <rest>, so
the clean command shows. Genuine app titles (claude, "lazygit: dormouse",
"README.md - VIM") are unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: d00c79c
Status: ✅  Deploy successful!
Preview URL: https://fe20a146.mouseterm.pages.dev
Branch Preview URL: https://conpty-titles.mouseterm.pages.dev

View logs

@nedtwigg nedtwigg merged commit c3ae873 into main May 27, 2026
9 checks passed
@nedtwigg nedtwigg deleted the conpty-titles branch May 27, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants